﻿using System.Net;
using System.Configuration;

namespace Alderamin.Core
{
    /// <summary>
    /// Stores the configuration of AlderaminClientProxy
    /// </summary>
    public class ClientProxyConfiguration : ApplicationSettingsBase
    {
        /// <summary>
        /// The key used to identify the user
        /// </summary>
        [UserScopedSetting()]
        public string AccessKey
        {
            get { return (string)this["AccessKey"]; }
            set { this["AccessKey"] = value; }
        }

        /// <summary>
        /// The local port opened for listening the browser request
        /// </summary>
        [UserScopedSetting()]
        [DefaultSettingValue("0")]
        public int LocalListenPort
        {
            get { return (int)this["LocalListenPort"]; }
            set
            {
                if (value == 0 || (value > 1023 && value < 65537))
                {
                    this["LocalListenPort"] = value;
                }
            }
        }

        /// <summary>
        /// The url of the script that handles http requests
        /// </summary>
        [UserScopedSetting()]
        public string HttpUrl
        {
            get { return (string)this["HttpUrl"]; }
            set { this["HttpUrl"] = value; }
        }

        /// <summary>
        /// The url of the script that initializes the enviroment of handling HTTPS request
        /// </summary>
        [UserScopedSetting()]
        public string HttpsStartUrl
        {
            get { return (string)this["HttpsStartUrl"]; }
            set { this["HttpsStartUrl"] = value; }
        }

        /// <summary>
        /// The url of the script that handles the HTTPS requests
        /// </summary>
        [UserScopedSetting()]
        public string HttpsMainUrl
        {
            get { return (string)this["HttpsMainUrl"]; }
            set { this["HttpsMainUrl"] = value; }
        }

        /// <summary>
        /// The url of the script that runs in the background to maintain the 
        /// tcp connection to the destination servers
        /// </summary>
        [UserScopedSetting()]
        public string HttpsRunningUrl
        {
            get { return (string)this["HttpsRunningUrl"]; }
            set { this["HttpsRunningUrl"] = value; }
        }

        /// <summary>
        /// The maximum number of running scripts can be executed at the same time.Default is 3.
        /// </summary>
        [UserScopedSetting()]
        [DefaultSettingValue("3")]
        public int HttpsMaxRunnings
        {
            get { return (int)this["HttpsMaxRunnings"]; }
            set
            {
                if (value > 0)
                {
                    this["HttpsMaxRunnings"] = value;
                }
            }
        }

        /// <summary>
        /// The web proxy used to send and receive the data
        /// </summary>
        [UserScopedSetting()]
        [DefaultSettingValue(null)]
        [SettingsSerializeAs(SettingsSerializeAs.Binary)]
        public WebProxy Proxy
        {
            get { return (WebProxy)this["Proxy"]; }
            set { this["Proxy"] = value; }
        }
    }
}
